﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Finance.Enums;
using mozhi.smarterp.Finance.Treasuries.Payments.Requisition;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Finance.Treasuries
{
    [RemoteService]
    [Route("api/v1/payment-requisitions")]
    public class PaymentRequisitionController : BaseController
    {
        private IPaymentRequisitionAppService _appService;

        public PaymentRequisitionController(IPaymentRequisitionAppService appService)
        {
            _appService = appService;
        }


        [HttpGet]
        [Route("{id}")]
        public async Task<PaymentRequisitionDto> GetAsync(Guid id)
        {
            var result = await _appService.GetAsync(id);

            return result;
        }

        [HttpGet]
        public async Task<PagedResultDto<PaymentRequisitionDto>> GetAsync(PaymentRequisitionPagedResultRequestDto filter)
        {
            var result = await _appService.GetListAsync(filter);

            return result;
        }

        [HttpPost]
        public async Task<PaymentRequisitionDto> CreateAsync(PaymentRequisitionCreateDto payment)
        {
            var result = await _appService.CreateAsync(payment);

            return result;
        }

        [HttpPut]
        public async Task<PaymentRequisitionDto> UpdateAsync(PaymentRequisitionUpdateDto payment)
        {
            var result = await _appService.UpdateAsync(payment);

            return result;
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpPost]
        [Route("{id}/payments")]
        public async Task<Guid> PushPaymentAsync(Guid id)
        {
           var paymentId = await _appService.PushPaymentAsync(id);

            return paymentId;
        }

        [HttpPut]
        [Route("{id}/status/{status}")]
        public async Task<PaymentRequisitionDto> UpdateStatusAsync(Guid id , DocumentStatusType status)
        {
            var requisitionDto = await _appService.UpdateStatusAsync(id , status);

            return requisitionDto;
        }
    }
}
